package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.controller.vo.Result;
import com.example.entity.Interaction;
import com.example.mapper.InteractionMapper;
import com.example.service.IInteractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 互动行为信息表 服务实现类
 * </p>
 *
 * @author yzy
 * @since 2025-08-04
 */
@Service
public class InteractionServiceImpl extends ServiceImpl<InteractionMapper, Interaction> implements IInteractionService {
    @Autowired
    private InteractionMapper interactionMapper;

    @Override
    public Page<Interaction> selectList(Page<Interaction> page, QueryWrapper<Interaction> queryWrapper) {
        Page<Interaction> page1 = interactionMapper.selectpage(page, queryWrapper);
        return page1;
    }

    @Override
    public Result removeByNameAndType(Integer userId, Integer type, Integer productId) {
        Interaction interaction = interactionMapper.selectProductIdsByUserIdAndTypeAndproductId(userId, type,productId);
        if(type==1){
            interactionMapper.deleteById(interaction.getId());
            return Result.success("已删除收藏");
        } else if(type==2){
            interactionMapper.deleteById(interaction.getId());
            return Result.success("已删除浏览记录");
        }else if(type==3){
            interactionMapper.deleteById(interaction.getId());
            return Result.success("已删除想要记录");
        }
        return Result.failed("type不符合要求");
    }
}
